import apis from '../../http/apis/apis'
export default {
    namespaced: true,
    state: {
        insuresInfo: [],
        totals: 0,
        // insuresRanderData: [],
        pageSize: 3,
        currentPage: 1,
    },
    mutations: {
        async getInsuresInfo(state, data) {
            state.insuresInfo = data.data
            state.totals = data.total
            // state.insuresRanderData = data.data
        },
        setpageSize(state, pageSize) {
            state.pageSize = pageSize
        },
        setcurrentPage(state, currentPage) {
            state.currentPage = currentPage
        }
    },
    actions: {
        //获取
        async getInsuresInfo(context) {
            let data = await apis.insures.getInsuresInfo({
                pageSize: context.state.pageSize,
                currentPage: context.state.currentPage
            })
            if (data.code) {
                context.commit('getInsuresInfo', data.data)
            }
        },

        //搜索
        async searchInsuresInfo(context, result) {
            let data = await apis.insures.searchInsures({
                pageSize: context.state.pageSize,
                currentPage: context.state.currentPage,
                insearchInsuranceValue: result.insearchInsuranceValue,
                type: result.type
            });
            if (data.code) {
                context.commit('getInsuresInfo', data.result)
                return data
            }
        },

        //新增
        async addInsuresInfo(context, result) {
            return await apis.insures.addInsuresInfo(result)
        },

        //删除
        async delInsureOne(context, _id) {
            return await apis.insures.deleteInsureOne(_id)
        },

        //修改
        async updateInsureOne(context, updateData) {
            return await apis.insures.updateInsures(updateData)
        }
    }
}